// components/price-info/price-info.js
Component({
  externalClasses: ['custom-class', 'price-class', 'price-interger-class'],
  /**
   * 组件的属性列表
   */
  properties: {
    mini: {
      type: Boolean,
      value: false
    },
    black: {
      type: Boolean,
      value: false
    },
    price: {
      type: null,
      observer: 'updatePrice',
    },
    decimalLength: {
      type: Number,
      value: 2,
      observer: 'updatePrice',
    },
    label: {
      type: String,
      value: ''
    },
    currency: {
      type: String,
      value: '￥'
    },
    lineThrough: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    integerStr: '',
    decimalStr: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    updatePrice: function () {
      var _a = this.data,
        price = _a.price,
        decimalLength = _a.decimalLength;
      var priceStrArr =
        typeof price === 'number' &&
        (price / 100).toFixed(decimalLength).split('.');
      this.setData({
        integerStr: priceStrArr && priceStrArr[0],
        decimalStr: decimalLength && priceStrArr ? '.' + priceStrArr[1] : '',
      });
    },
  }
})
